package com.rfid.library.zhongshan;

public class BookIndex
    {
    private String m_TagId;


    private String m_BookIndex;
    private String m_BookName;
    private String m_BookPlace;
    private String m_BookID;

    /// <summary>
    /// 以/分割索书号的字符数组
    /// </summary>
    private String[] lines;

    /// <summary>
    /// lines数组的长度
    /// </summary>
    private int lineNum;

    /// <summary>
    /// 类别号
    /// </summary>
    private ClassNo classNo;

    /// <summary>
    /// 著者号、种次号
    /// </summary>
    public AuthorNo authorNo;

    /// <summary>
    /// 卷册年
    /// </summary>
    public VolumeOrYear volumeOryear;

    //是否有效
    public boolean format;

    /// <summary>
    /// 比较过程
    /// </summary>
    public static String message;

//    /// <summary>
//    /// 数据同步过程消息委托
//    /// </summary>
//    /// <param name="sender"></param>
//    /// <param name="e"></param>
//    public delegate void SendMsgEventHandler(object sender, String message);
//    //委托，发送消息到调用端
//    private SendMsgEventHandler m_send_msg;
//    public SendMsgEventHandler SendMsg
//    {
//        get { return m_send_msg; }
//        set { m_send_msg = value; }
//    }

    /// <summary>
    /// 初始化
    /// </summary>
    /// <param name="i_bookIndex"></param>
    /// <param name="i_bookName"></param>
    /// <param name="i_bookPlace"></param>
    /// <param name="i_bookID"></param>
    /// <param name="i_tagID"></param>
    public BookIndex(String i_bookIndex, String i_bookName, String i_bookPlace, String i_bookID, String i_tagID)
    {
        try
        {
            this.m_BookIndex = i_bookIndex.toUpperCase();
            m_BookIndex = m_BookIndex.replace('－', '-')
                .replace('＝', '=')
                .replace('：', ':')
                .replace('＋', '+')
                .replace('＃', '#')
                .replace('＊', '*')
                .replace('（', '(').replace('）', ')');

            this.m_BookName = i_bookName;
            this.m_BookPlace = i_bookPlace;
            this.m_BookID = i_bookID;
            this.m_TagId = i_tagID;

            lines = m_BookIndex.split("/");
            lineNum = lines.length;
            classNo = new ClassNo(lines[0]);
            if (lineNum >= 1)
            {
                authorNo = new AuthorNo(lines[1]);
            }
            else
            {
                authorNo = new AuthorNo("");
            }

            if (lineNum > 2)
            {
                volumeOryear = new VolumeOrYear(lines[2]);
            }
            else
            {
                volumeOryear = new VolumeOrYear("");
            }
            format = true;
        }
        catch (Exception e){ format = false;  }
    }
    
    /// <summary>
    /// 比较索书号大小
    /// </summary>
    /// <param name="o"></param>
    /// <returns></returns>
    public int CompareTo(Object o)
    {
        try
        {
            BookIndex end = (BookIndex)o;
            BookIndex.Fun_Message("开始比较大小...\r\n\r\n");
//            #region 分类号
            int tmp = classNo.CompareTo(end.classNo);
            if (tmp != 0)
            {
                if (tmp > 0)
                {
                     Fun_Message("比较结果：" + classNo.cnStr + " > " + end.classNo.cnStr + "\r\n\r\n");
                }
                else
                {
                     Fun_Message("比较结果：" + classNo.cnStr + " < " + end.classNo.cnStr + "\r\n\r\n");
                }
                return tmp;
            }
            else
            {
                 Fun_Message("比较结果：" + classNo.cnStr + " = " + end.classNo.cnStr + "\r\n\r\n");
            }

//            #region 著者号/种次号
            tmp = authorNo.CompareTo(end.authorNo);

            if (tmp != 0)
            {
                if (tmp > 0)
                {
                    Fun_Message("比较结果：" + authorNo.anStr + " > " + end.authorNo.anStr + "\r\n\r\n");
                }
                else
                {
                     Fun_Message("比较结果：" + authorNo.anStr + " < " + end.authorNo.anStr + "\r\n\r\n");
                }
                return tmp;
            }
            else
            {
                 Fun_Message("比较结果：" + authorNo.anStr + " = " + end.authorNo.anStr + "\r\n\r\n");
            }

//            #region 卷册号
            int count = 2;

            if ((lineNum == end.lineNum) && (lineNum == count))
            {
                return 0;
            }
            if ((lineNum == count) && (end.lineNum > lineNum))
            {
                return -1;
            }
            if ((end.lineNum == count) && (end.lineNum < lineNum))
            {
                return 1;
            }
            tmp = volumeOryear.CompareTo(end.volumeOryear);
            if (tmp != 0)
            {
                if (tmp > 0)
                {
                    Fun_Message("比较结果：" + volumeOryear.cnStr + " > " + end.volumeOryear.cnStr + "\r\n\r\n");
                }
                else
                {
                    Fun_Message("比较结果：" + volumeOryear.cnStr + " < " + end.volumeOryear.cnStr + "\r\n\r\n");
                }
                return tmp;
            }
            else
            {
                Fun_Message("比较结果：" + volumeOryear.cnStr + " = " + end.volumeOryear.cnStr + "\r\n\r\n");
            }
            //SendMsg2Client(message);
            return tmp;
        }
        catch (Exception e){ return 0; }
    }

    /// <summary>
    /// 发送消息到调用端
    /// </summary>
    /// <param name="i_msg"></param>
//    public void SendMsg2Client(String i_msg)
//    {
//        if (SendMsg != null)
//        {
//            SendMsg(this, i_msg);
//        }
//    }

    /// <summary>
    /// 更新信息
    /// </summary>
    /// <param name="i_message"></param>
    public static void Fun_Message(String i_message)
    {
//        message += i_message;
        System.out.println(i_message);
    }

}
        